﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Zorbo.Interface
{
    public interface IServerHistory
    {
        /// <summary>
        /// Gets an IReadOnlyList&lt;Regex&gt; of admin passwords
        /// </summary>
        IReadOnlyList<IPassword> Passwords { get; }
        /// <summary>
        /// Gets an IReadOnlyList&lt;Regex&gt; of banned dns names
        /// </summary>
        IReadOnlyList<Regex> DnsBans { get; }
        /// <summary>
        /// Gets an IReadOnlyList&lt;Regex&gt; of banned ip ranges
        /// </summary>
        IReadOnlyList<Regex> RangeBans { get; }
        /// <summary>
        /// Gets an IReadOnlyList&lt;IClientRecord&gt; of user history recrods
        /// </summary>
        IReadOnlyList<IRecord> Records { get; }
        /// <summary>
        /// Checks to see if the DNS entry is banned
        /// </summary>
        bool IsDnsBanned(IPHostEntry entry);
        /// <summary>
        /// Checks an IPAddress to see if it belongs to a banned range
        /// </summary>
        bool IsRangeBanned(IPAddress address);
        /// <summary>
        /// Registers an adminstrator password with the server
        /// </summary>
        bool RegisterPassword(string password, AdminLevel level);
        /// <summary>
        /// Modifies the admin level of a password on record
        /// </summary>
        bool ModifyPassword(string password, AdminLevel level);
        /// <summary>
        /// Logs a user in using the supplied password
        /// </summary>
        IPassword CheckPassword(string password);
        /// <summary>
        /// Checks the sha1 admnistrator login of a user
        /// </summary>
        IPassword CheckSha1Password(IClient client, byte[] password);
        /// <summary>
        /// Clears the entire user history
        /// </summary>
        void Clear();
        /// <summary>
        /// Clears the user history of all bans
        /// </summary>
        void ClearBanned();
        /// <summary>
        /// Clears all dns ban regular expressions
        /// </summary>
        void ClearDnsBans();
        /// <summary>
        /// Clears all range ban regular expressions
        /// </summary>
        void ClearRangeBans();
        /// <summary>
        /// Bans a connected user from the room (<see cref="IClient.Ban"/> is equivalent, but disconnects the user)
        /// </summary>
        bool BanUser(IClient user);
        /// <summary>
        /// Unbans the first user in the history matching the specified predicate
        /// </summary>
        bool UnbanUser(Predicate<IRecord> match);
        /// <summary>
        /// Bans a DNS name by the supplied regular expression. Regular 
        /// expressions are a more powerful matching option for plugins 
        /// and requiring a regular expression at interface level instead of a string 
        /// ensures that the regex being supplied is valid
        /// </summary>
        bool BanDns(Regex dnsban);
        /// <summary>
        /// Unbans a DNS name by the suppled regular expression
        /// </summary>
        bool UnbanDns(Regex dnsban);
        /// <summary>
        /// Bans an IP range by the supplied regular expression. Regular 
        /// expressions are a more powerful matching option for plugins 
        /// and requiring a regular expression at interface level instead of a string 
        /// ensures that the regex being supplied is valid
        /// </summary>
        bool BanRange(Regex rangeban);
        /// <summary>
        /// Unbans an IP range by the supplied regular expression
        /// </summary>
        bool UnbanRange(Regex rangeban);
        /// <summary>
        /// Gets the IClientRecord associated with the specified user
        /// </summary>
        IRecord GetRecord(IClient user);
        /// <summary>
        /// Searches the user history for a record meeting the criteria of the supplied predicate
        /// </summary>
        IRecord FindRecord(Predicate<IRecord> match);
    }
}
